﻿#region 头注释
/******************************************************************************
文件名称    :   ChemistryLymphocyte.cs
创建日期    :   2011/5/11 22:16:41
功能描述    :   ChemistryLymphocyte实体类
修改日志    :   
    2011-05-11 22:16  马利
*******************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Newtonsoft.Json;
using Dare.Utilities.Data;

namespace Stone.Components.Entities
{
    /// <summary>
    /// ChemistryLymphocyte实体类
    /// </summary>
    public class ChemistryLymphocyte : EntityBase<ChemistryLymphocyte, long>
    {
        #region 构造函数

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ChemistryLymphocyte()
            : base()
        {
            base.xmlSerializer = new DefaultXmlSerializer(this);
            base.jsonSerializer = new DefaultJsonSerializer(this);
        }

        public override void Reset()
        {
            cd3 = null;
            cd4 = null;
            cd8 = null;
            cd19 = null;
            cd1656 = null;
            hs = null;
            tBNk = null;
            comment = null;
            timeStamp = DateTime.MinValue;
        }

        public override ChemistryLymphocyte CreateNew()
        {
            return new ChemistryLymphocyte();
        }

        #endregion

        #region 属性

        /// <summary>
        /// 获取实体类型
        /// </summary>
        public override EntityType EntityType
        {
            get { return EntityType.ChemistryLymphocyte; }
        }

        /// <summary>
        /// 获取或设置Cd3
        /// </summary>
        public decimal? Cd3
        {
            get { return cd3; }
            set
            {
                if (entityState == EntityState.Saved && cd3 != value) entityState = EntityState.Changed;
                cd3 = value;
            }
        }
        protected decimal? cd3;

        /// <summary>
        /// 获取或设置Cd4
        /// </summary>
        public decimal? Cd4
        {
            get { return cd4; }
            set
            {
                if (entityState == EntityState.Saved && cd4 != value) entityState = EntityState.Changed;
                cd4 = value;
            }
        }
        protected decimal? cd4;

        /// <summary>
        /// 获取或设置Cd8
        /// </summary>
        public decimal? Cd8
        {
            get { return cd8; }
            set
            {
                if (entityState == EntityState.Saved && cd8 != value) entityState = EntityState.Changed;
                cd8 = value;
            }
        }
        protected decimal? cd8;

        /// <summary>
        /// 获取或设置Cd19
        /// </summary>
        public decimal? Cd19
        {
            get { return cd19; }
            set
            {
                if (entityState == EntityState.Saved && cd19 != value) entityState = EntityState.Changed;
                cd19 = value;
            }
        }
        protected decimal? cd19;

        /// <summary>
        /// 获取或设置Cd1656
        /// </summary>
        public decimal? Cd1656
        {
            get { return cd1656; }
            set
            {
                if (entityState == EntityState.Saved && cd1656 != value) entityState = EntityState.Changed;
                cd1656 = value;
            }
        }
        protected decimal? cd1656;

        /// <summary>
        /// 获取或设置HS
        /// </summary>
        public decimal? HS
        {
            get { return hs; }
            set
            {
                if (entityState == EntityState.Saved && hs != value) entityState = EntityState.Changed;
                hs = value;
            }
        }
        protected decimal? hs;

        /// <summary>
        /// 获取或设置TBNk
        /// </summary>
        public decimal? TBNk
        {
            get { return tBNk; }
            set
            {
                if (entityState == EntityState.Saved && tBNk != value) entityState = EntityState.Changed;
                tBNk = value;
            }
        }
        protected decimal? tBNk;

        /// <summary>
        /// 获取或设置备注
        /// </summary>
        public string Comment
        {
            get { return comment; }
            set
            {
                if (entityState == EntityState.Saved && comment != value) entityState = EntityState.Changed;
                comment = value;
            }
        }
        protected string comment;

        /// <summary>
        /// 获取或设置更新时间戳
        /// </summary>
        public DateTime TimeStamp
        {
            get { return timeStamp; }
            set
            {
                if (entityState == EntityState.Saved && timeStamp != value) entityState = EntityState.Changed;
                timeStamp = value;
            }
        }
        protected DateTime timeStamp;

        #endregion

        #region 方法

        #endregion

        #region 实体复制相关方法

        /// <summary>
        /// 复制当前实体属性到指定实体上
        /// </summary>
        /// <param name="entity">要把属性复制到的实体</param>
        /// <returns>返回传入的实体</returns>
        public override ChemistryLymphocyte CopyTo(ChemistryLymphocyte entity)
        {
            if (base.CopyTo(entity) == null) return null;

            entity.cd3 = this.cd3;
            entity.cd4 = this.cd4;
            entity.cd8 = this.cd8;
            entity.cd19 = this.cd19;
            entity.cd1656 = this.cd1656;
            entity.hs = this.hs;
            entity.tBNk = this.tBNk;
            entity.comment = this.comment;
            entity.timeStamp = this.timeStamp;

            return entity;
        }

        #endregion

        #region 默认XML序列器类

        public class DefaultXmlSerializer : XmlSerializerBase, IEntityXmlSerializer<ChemistryLymphocyte>
        {
            ChemistryLymphocyte entity;
            public DefaultXmlSerializer(ChemistryLymphocyte entity)
                : base(entity.GetType().Name)
            {
                this.entity = entity;
            }

            public ChemistryLymphocyte Entity
            {
                get { return entity; }
                set { entity = value; }
            }

            protected override void BeforeReadXml()
            {
                entity.Reset();
            }

            /// <summary>
            /// 读取XML属性
            /// </summary>
            /// <param name="name">属性名</param>
            /// <param name="value">属性值</param>
            /// <param name="reader">XML读取器</param>
            internal override void ReadXmlAttribute(string name, string value, XmlReader reader)
            {
                switch (name)
                {
                    case "id":
                        entity.id = XmlConvert.ToInt64(value);
                        break;
                    case "timeStamp":
                        entity.timeStamp = new DateTime(long.Parse(value));
                        break;
                    case "entityState":
                        entity.entityState = (EntityState)Enum.Parse(typeof(EntityState), value, true);
                        break;
                }
            }

            /// <summary>
            /// 读取XML子节点
            /// </summary>
            /// <param name="name">节点名</param>
            /// <param name="reader">XML读取器</param>
            internal override void ReadXmlChildElement(string name, XmlReader reader)
            {
                switch (name)
                {
                    case "Cd3":
                        entity.cd3 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Cd4":
                        entity.cd4 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Cd8":
                        entity.cd8 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Cd19":
                        entity.cd19 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Cd1656":
                        entity.cd1656 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "HS":
                        entity.hs = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "TBNk":
                        entity.tBNk = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Comment":
                        entity.comment = reader.ReadElementString();
                        break;
                }
            }

            /// <summary>
            /// 写入XML属性
            /// </summary>
            /// <param name="writer">XML编写器</param>
            internal override void WriteXmlAttributes(XmlWriter writer)
            {
                writer.WriteAttributeString("id", XmlConvert.ToString(entity.Id));
                writer.WriteAttributeString("timeStamp", entity.TimeStamp.Ticks.ToString());
                writer.WriteAttributeString("entityState", entity.EntityState.ToString());
            }

            /// <summary>
            /// 写入XML子节点
            /// </summary>
            /// <param name="writer">XML编写器</param>
            internal override void WriteXmlChildElements(XmlWriter writer)
            {
                if (entity.Cd3 != null) writer.WriteElementString("Cd3", XmlConvert.ToString(entity.Cd3.Value));
                if (entity.Cd4 != null) writer.WriteElementString("Cd4", XmlConvert.ToString(entity.Cd4.Value));
                if (entity.Cd8 != null) writer.WriteElementString("Cd8", XmlConvert.ToString(entity.Cd8.Value));
                if (entity.Cd19 != null) writer.WriteElementString("Cd19", XmlConvert.ToString(entity.Cd19.Value));
                if (entity.Cd1656 != null) writer.WriteElementString("Cd1656", XmlConvert.ToString(entity.Cd1656.Value));
                if (entity.HS != null) writer.WriteElementString("HS", XmlConvert.ToString(entity.HS.Value));
                if (entity.TBNk != null) writer.WriteElementString("TBNk", XmlConvert.ToString(entity.TBNk.Value));
                if (entity.Comment != null) writer.WriteElementString("Comment", entity.Comment);
            }
        }

        #endregion

        #region 默认Json序列化器类

        public class DefaultJsonSerializer : JsonSerializerBase, IEntityJsonSerializer<ChemistryLymphocyte>
        {
            ChemistryLymphocyte entity;
            public DefaultJsonSerializer(ChemistryLymphocyte entity)
                : base()
            {
                this.entity = entity;
            }

            public ChemistryLymphocyte Entity
            {
                get { return entity; }
                set { entity = value; }
            }

            /// <summary>
            /// 读取JSON属性
            /// </summary>
            /// <param name="propName">属性名称</param>
            /// <param name="propValue">属性值</param>
            /// <param name="reader">JSON读取器</param>
            protected override void ReadJsonProperty(string propName, object propValue, JsonReader reader)
            {
                switch (propName)
                {
                    case "id":
                        entity.id = DbConvert.ToNullableInt64(propValue) ?? entity.id;
                        break;
                    case "cd3":
                        entity.cd3 = DbConvert.ToNullableDecimal(propValue) ?? entity.cd3;
                        break;
                    case "cd4":
                        entity.cd4 = DbConvert.ToNullableDecimal(propValue) ?? entity.cd4;
                        break;
                    case "cd8":
                        entity.cd8 = DbConvert.ToNullableDecimal(propValue) ?? entity.cd8;
                        break;
                    case "cd19":
                        entity.cd19 = DbConvert.ToNullableDecimal(propValue) ?? entity.cd19;
                        break;
                    case "cd1656":
                        entity.cd1656 = DbConvert.ToNullableDecimal(propValue) ?? entity.cd1656;
                        break;
                    case "hs":
                        entity.hs = DbConvert.ToNullableDecimal(propValue) ?? entity.hs;
                        break;
                    case "tBNk":
                        entity.tBNk = DbConvert.ToNullableDecimal(propValue) ?? entity.tBNk;
                        break;
                    case "comment":
                        entity.comment = Convert.ToString(propValue) ?? entity.comment;
                        break;
                    case "timeStamp":
                        entity.timeStamp = new DateTime(DbConvert.ToNullableInt64(propValue) ?? 0);
                        break;
                }
            }

            /// <summary>
            /// 写入JSON属性
            /// </summary>
            /// <param name="writer">JSON编写器</param>
            protected override void WriteJsonProperties(JsonWriter writer)
            {

                //Id
                writer.WritePropertyName("id");
                writer.WriteValue(entity.Id);

                //Cd3
                writer.WritePropertyName("cd3");
                if (entity.Cd3 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Cd3.Value);
                }

                //Cd4
                writer.WritePropertyName("cd4");
                if (entity.Cd4 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Cd4.Value);
                }

                //Cd8
                writer.WritePropertyName("cd8");
                if (entity.Cd8 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Cd8.Value);
                }

                //Cd19
                writer.WritePropertyName("cd19");
                if (entity.Cd19 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Cd19.Value);
                }

                //Cd1656
                writer.WritePropertyName("cd1656");
                if (entity.Cd1656 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Cd1656.Value);
                }

                //HS
                writer.WritePropertyName("hs");
                if (entity.HS == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.HS.Value);
                }

                //TBNk
                writer.WritePropertyName("tBNk");
                if (entity.TBNk == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.TBNk.Value);
                }

                //备注
                writer.WritePropertyName("comment");
                if (entity.Comment == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Comment);
                }

                //更新时间戳
                writer.WritePropertyName("timeStamp");
                writer.WriteValue(entity.TimeStamp.Ticks);
            }
        }


        #endregion
    }
}